<?php
/**
 * Description:
 *
 * @author      Eden
 * @datetime    2017/4/4 16:41
 * @copyright   WuHan HuQi Technology Co.,Ltd.
 * @url         http://cnhuqi.com
 */

class Upload extends ADM_Controller
{
    /**
     * 初始化
     */
    public function __construct()
    {
        parent::__construct();
    }

    public function up()
    {
        $send['state'] = false;
        do {

            $thumbWidth = 100;
            $thumbHeight = 100;

            if ($this->input->method(true) !== 'POST') {
                $send['error'] = '非法请求';
                break;
            }

            $width = $this->input->get('width');
            $height = $this->input->get('height');
            if (!empty($width) && !empty($height)) {
                $thumbWidth = intval($width);
                $thumbHeight = intval($height);
            }

            $res = local($_FILES['file']);
            if (empty($res)) {
                $send['error'] = '上传失败';
            } else {
                $send['state'] = true;
                $send['data'] = array_merge($res, array(
                    'thumb' => thumb($res['key'], $thumbWidth, $thumbHeight),
                    'source' => thumb($res['key']),
                ));
            }
        } while(false);
        $this->output->send($send);
    }
}
